package com.hc.model.utils;

import com.hc.DTO.SysAnimalDTO;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class SysAnimalModel {
	public static SysAnimalModel instance;

	public static SysAnimalModel getInstance() {
		if (instance == null)
			instance = new SysAnimalModel();
		return instance;
	}

	public boolean getLastDay(Context context, String _date) {
		boolean flag = false;
		String sql = "SELECT * FROM sysAnimal where Date(dateupdate) > Date('"
				+ _date + "')";
		DBHelper db = new DBHelper(context);
		Cursor c = db.Excutequery(sql);

		flag = c.moveToLast() == true;
		c.close();
		return flag;
	}

	public SysAnimalDTO getLastTwoDay(Context context) {
		SysAnimalDTO dto = new SysAnimalDTO();
		String sql = "SELECT * FROM sysAnimal";
		DBHelper db = new DBHelper(context);
		Cursor c = db.Excutequery(sql);
		while (c.moveToNext()) {
			dto.setCurrentday(c.getString(c.getColumnIndex("currentday")));
			dto.setDateupdate(c.getString(c.getColumnIndex("dateupdate")));
		}
		c.close();
		db.close();

		return dto;
	}

	public boolean updateSysAnimal(SysAnimalDTO dto, Context context) {
		boolean flag = false;
		// String sql = "UPDATE changelog SET Id=" + id;
		DBHelper db = new DBHelper(context);
		ContentValues values = new ContentValues();
		values.put("dateupdate", dto.getDateupdate());
		values.put("currentday", dto.getCurrentday());
		flag = db.ExcuteUpdate(null, "sysAnimal", values, "1 = 1", null);
		db.close();
		return flag;
	}
}
